package com.ruan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruan.entity.Order;
import com.ruan.entity.Question;
import com.ruan.entity.R;
import com.ruan.query.QuestionQuery;
import com.ruan.service.QuestionService;
import com.ruan.mapper.QuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 59499
* @description 针对表【tb_question】的数据库操作Service实现
* @createDate 2023-09-20 15:00:05
*/
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
    implements QuestionService{

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public R<IPage<Question>> queryQuestions(QuestionQuery questionQuery) {
        QueryWrapper<Question> wrapper = new QueryWrapper<>();
        if (questionQuery.getSearchValue() != null && !Objects.equals(questionQuery.getSearchValue(), "")){
            wrapper.like("title",questionQuery.getSearchValue());
        }
        Page<Question> questionPage = new Page<>(questionQuery.getPage(),questionQuery.getSize());
        IPage<Question> questionIPage = questionMapper.selectPage(questionPage,wrapper);
        return R.ok("查询成功",questionIPage);
    }
}




